package com.sctvcloud.qingchuan.ui.adapter.holder;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.widget.ImageView;

import com.gridsum.tracker.GridsumWebDissector;
import com.iflytek.cloud.thirdparty.V;
import com.ruihang.generalibrary.ui.adapter.holder.BaseRecylerHolder;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.ruihang.generalibrary.ui.widget.CustomEXImageView;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.ruihang.generalibrary.utils.DateUtils;
import com.sctvcloud.qingchuan.R;
import com.sctvcloud.qingchuan.beans.FRebellion;
import com.sctvcloud.qingchuan.beans.GovDetailBean;
import com.sctvcloud.qingchuan.beans.NewsItem;
import com.sctvcloud.qingchuan.ui.activities.GovDetailActivity;
import com.sctvcloud.qingchuan.ui.utils.ControlMediaViewHelper;
import com.sctvcloud.qingchuan.ui.utils.GlideUtil;
import com.sctvcloud.qingchuan.ui.utils.Hour24GetHelper;
import com.sctvcloud.qingchuan.ui.utils.SkipUtil;
import com.sctvcloud.qingchuan.ui.utils.UIUtils;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/26 0026.
 */

public class GovDetailHolder extends BaseAbsHolder<NewsItem> implements View.OnClickListener {
    private OnItemInternalClick onItemInternalClick;

    @BindView(R.id.item_name)
    protected CustomFontTextView item_name;
    @BindView(R.id.tv_time)
    protected CustomFontTextView tv_time;
    @BindView(R.id.item_city_state_news_img)
    protected CustomEXImageView item_city_state_news_img;
    @BindView(R.id.tv_reader)
    protected CustomFontTextView tv_reader;
    @BindView(R.id.news_tag)
    protected ImageView news_tag;

    private String titleName;
    private NewsItem newsItem;
    private Activity activity;

    private ControlMediaViewHelper mControlMediaViewHelper;

    public GovDetailHolder(Context context, View itemView) {
        super(context, itemView);
        itemView.setOnClickListener(this);
    }


    public void setActivity(Activity activity) {
        this.activity = activity;
    }


    @Override
    public void setData(NewsItem data) {
        this.newsItem = data;
        if (!TextUtils.isEmpty(data.getNewsImage())) {
            GlideUtil.getGlideWithSmall169DefCenterCrop(context, data.getNewsImage()).into(item_city_state_news_img);
            item_city_state_news_img.setVisibility(View.VISIBLE);
            item_name.setLines(3);
        } else {
            item_city_state_news_img.setVisibility(View.GONE);
            item_name.setMaxLines(2);
        }


//        if (data.getNewsType() == 2) { //音频
//            news_tag.setImageResource(R.mipmap.icon_home_voice);
//            news_tag.setVisibility(View.VISIBLE);
//        } else if (data.getNewsType() == 3) {   //视频
//            news_tag.setImageResource(R.mipmap.icon_home_play);
//            news_tag.setVisibility(View.VISIBLE);
//        }  else {
//            news_tag.setVisibility(View.GONE);
//        }
        news_tag.setVisibility(View.GONE);
        mControlMediaViewHelper.setMedia(newsItem.getNewsType(), newsItem.getDataMediaLength(), !TextUtils.isEmpty(data.getNewsImage()));

        item_name.setText(TextUtils.isEmpty(data.getNewsTitle()) ? "" : data.getNewsTitle());
        titleName = item_name.getText().toString();

        tv_time.setText(!TextUtils.isEmpty(data.getPubTime()) ? DateUtils.formatDate(DateUtils.getDataDate(data), "MM-dd HH:mm") : "");
        tv_reader.setText(UIUtils.getReadingNumber(data.getViews()));
    }


    @Override
    protected void initInject() {
        ButterKnife.bind(this, itemView);
        mControlMediaViewHelper = new ControlMediaViewHelper(itemView);
    }

    public GovDetailHolder setOnItemInternalClick(OnItemInternalClick onItemInternalClick) {
        this.onItemInternalClick = onItemInternalClick;
        return this;
    }

    @Override
    public void onClick(View v) {
        ArrayList<Pair<String, String>> pairs = new ArrayList<>();
        pairs.add(new Pair<>("页面", "首页"));
        pairs.add(new Pair<>("栏目", "政务/乡镇"));
        pairs.add(new Pair<>("位置", "专题名称"));
        ArrayList<Pair<String, String>> pairsMap = new ArrayList<>();
        pairsMap.addAll(pairs);
        pairsMap.add(new Pair<>("行为类型", "点击"));
        GridsumWebDissector.getInstance().trackEvent(activity, "", titleName, "", 200, pairsMap);
        HashMap<String, String> map = new HashMap<>();
        for (Pair<String, String> p : pairs) {
            map.put(p.first, p.second);
        }
        SkipUtil.skipWithNewsItem(context, newsItem, map);
    }
}

